<link rel="stylesheet" href="${basePath}/resources/common/libs/datetimepicker/css/bootstrap-datetimepicker.min.css"/>
<link rel="stylesheet" href="${basePath}/resources/common/libs/fileinput/css/fileinput.min.css">
<script src="${basePath}/resources/common/libs/fileinput/js/fileinput.js"></script>
<script src="${basePath}/resources/common/libs/fileinput/js/locales/zh.js"></script>
<script src="${basePath}/resources/common/js/base-file.js"></script>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-remove"></li></button>
    <h5 class="modal-title"></h5>
</div>

<div class="modal-body">


<div class="col-md-12" style="float:none;">
	<div class="nav-tabs-custom">
		<ul class="nav nav-tabs">
			<li class="active"><a href="#tab_1" data-toggle="tab">新增&编辑页面</a></li>
			<li><a href="#tab_2" data-toggle="tab">图片上传</a></li>
		</ul>
		<div class="tab-content">
			<div class="tab-pane active" id="tab_1">
				
				
				<form id="${htmlPrefix}_form" name="${htmlPrefix}_form" class="form-horizontal">
			        <input type="hidden" name="id">
			        <input type="hidden" id="fileids" name="fileids"/>
			        <input type="hidden" name="parent" value="${parent}">
			        <input type="hidden" name="pnode" value="${pnodeId}">
			        <div class="box-body">
			            <#list 0..colsNum-1 as index>
			            <div class="col-md-${12/colsNum}">
			            <#list fields as field>
			                <#if field_index%colsNum=index>
			                <div class="form-group">
			                    <label class="col-sm-3 control-label">${field.labelName}<#if field.validateType??&&field.validateType?contains("notEmpty")><span style="color:red">*</span></#if></label>
			                    <div class="<#if field.tagType="datepicker" || field.tagType="datetimepicker">input-group </#if>col-sm-8">
			                        <#if field.tagType="hidden">
			                        <input type="hidden" id="${field.columnName}" name="${field.columnName}" >
			                        <#elseif field.tagType="textarea">
			                        <textarea name="${field.columnName}" id="${field.columnName}" placeholder="请填写${field.labelName}" class="form-control"></textarea>
			                        <#elseif field.tagType="datepicker">
			                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
			                        <input type="text" placeholder="请填写${field.labelName}" name="${field.columnName}" id="${field.columnName}" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
			                        <#elseif field.tagType="datetimepicker">
			                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
			                        <input type="text" placeholder="请填写${field.labelName}" name="${field.columnName}" id="${field.columnName}" data-flag="datetimepicker" class="form-control" data-format="yyyy-mm-dd hh:ii:ss">
			                        <#elseif field.tagType="dictSelector">
			                        <select name="${field.columnName}" id="${field.columnName}" data-code="${field.dictCode}"  data-flag="dictSelector" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:100%" data-blank="true"></select>
			                        <#elseif field.tagType="urlSelector">
			                        <select name="${field.columnName}" id="${field.columnName}" data-src="${field.dictCode}" data-flag="urlSelector" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:100%" data-blank="true"></select>
			                        <#elseif field.tagType="normalSelector">
			                        <select name="${field.columnName}" id="${field.columnName}" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:100%" data-blank="true">
			                            <option></option>
			                            <option value="0">否</option>
			                            <option value="1">是</option>
			                        </select>
			                        <#elseif field.tagType="radio">
			                            <#if !field.dictCode??>
			                        <label class="control-label"> <input type="radio" name="${field.columnName}"  value="1"> 是</label> &nbsp;
			                        <label class="control-label"> <input type="radio" name="${field.columnName}"  value="0"> 否</label>
			                            <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
			                        <input type="radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
			                            <#else>
			                        <input type="radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
			                            </#if>
			                        <#elseif field.tagType="icheck-radio">
			                            <#if !field.dictCode??>
			                        <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-blue" value="1"> 是</label> &nbsp;
			                        <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-blue" value="0"> 否</label>
			                            <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
			                        <input type="icheck-radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
			                            <#else>
			                        <input type="icheck-radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
			                            </#if>
			                        <#elseif field.tagType="checkbox">
			                            <#if !field.dictCode??>
			                        <label class="control-label"> <input type="checkbox" name="${field.columnName}" value="1"> 是</label> &nbsp;
			                        <label class="control-label"> <input type="checkbox" name="${field.columnName}"  value="0"> 否</label>
			                            <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
			                        <input type="checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
			                            <#else>
			                        <input type="checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
			                            </#if>
			                        <#elseif field.tagType="icheck-checkbox">
			                            <#if !field.dictCode??>
			                        <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-blue" value="1"> 是</label> &nbsp;
			                        <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-blue" value="0"> 否</label>
			                            <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
			                        <input type="icheck-checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
			                             <#else>
			                        <input type="icheck-checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
			                              </#if>
			                        <#else>
			                        <input type="text" class="form-control" id="${field.columnName}" name="${field.columnName}" placeholder="请填写${field.labelName}">
			                        </#if>
			                    </div>
			                </div>
			                </#if>
			            </#list>
			            </div>
			            </#list>
			        </div>
			        <div class="box-footer text-right">
			            <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal">取消</button>
			            <button type="submit" class="btn btn-primary" data-btn-type="save">提交</button>
			        </div>
			    </form>
				
				
			</div>
			<div class="tab-pane" id="tab_2">
				<div class="form-group" id="file_container">
				    <input type="file" name="file" id="attachment">
				</div>
			</div>
		</div>
	</div>
</div>



    
</div>
<script src="${basePath}/resources/common/libs/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="${basePath}/resources/common/libs/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script>
    var form;
    var id="${id?default(0)}";
    $(function(){
        //初始化表单
        form=$("#${htmlPrefix}_form").form();
        //数据校验
        $("#${htmlPrefix}_form").bootstrapValidator({
            message : '请输入有效值',
            feedbackIcons : {
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            submitHandler : function() {
                modals.confirm('确认保存？', function() {
                    var ${htmlPrefix} = form.getFormSimpleData();
                    <#assign isObj=1>
                    <#list fields as field>
                        <#if field.columnName?contains(".")>
                    <#assign isObj=0>
                        </#if>
                    </#list>
                    ajaxPost(basePath+'/dform/save',<#if isObj=1>${htmlPrefix}<#else>{"obj":JSON.stringify(${htmlPrefix})}</#if>, function(data) {
                        if(data.success){
                            if(id!="0"){
                                modals.hideWin(winId);
                                ${nodeName}Table.reloadRowData(id);
                            }else{
                                modals.hideWin(winId);
                                ${nodeName}Table.reloadData();
                            }
                        }
                    });
                });
            },
            fields : {
            <#list fields as field>
            <#if field.validateType??&&field.validateType!="">
                "${field.columnName}":{
                    validators:{
                        ${field.validateType}
                    }
                }<#if field_index+1<fields?size>,</#if>
            </#if>
            </#list>
            }
        });
        //初始化控件
        form.initComponent();
        //编辑回填
        if(id!=0){
            ajaxPost(basePath+"/dform/get/"+id + "?pnode=${pnodeId}",null,function(data){
                form.initFormData(data);
            })
        }
    });

    
    $("#attachment").file({
	    fileinput: {
	        maxFileSize: 10240,
	        maxFileCount:3
	    },
	    fileIdContainer:"[name='fileids']",
	    window:false
	});
    
</script>
